const express = require('express')
const app = express()

// 解决跨域问题
const cors = require('cors')
app.use(cors())

const getRouter = require('./get/index.js')
app.use('/api', getRouter)

const postRouter = require('./post/index.js')
app.use('/api', postRouter)

const { dirPath, pathPrefix } = require('./config.js')
app.use(pathPrefix, express.static(dirPath))

const errorMiddleware = (err, req, res, next) => {
  res.send({
    status: 1,
    msg: err.message
  })
}
app.use(errorMiddleware)

app.listen(80, () => {
  console.log('Server running at http://127.0.0.1')
})
